<?php
function htmlspec($src) {
	return htmlspecialchars($src, ENT_COMPAT, 'UTF-8');
}

function get_avatar_name($user_id, $rand = FALSE) {
	$fn = $_SERVER['DOCUMENT_ROOT'] . '/img/avatars/avt_' . $user_id . '_48x48.jpg';
	if(file_exists($fn)) {
		if($rand) {
			return 'avt_' . $user_id . '_48x48.jpg?R=' . rand();
		} else {
			return 'avt_' . $user_id . '_48x48.jpg';
		}
	} else {
		return 'avt_-1_48x48.jpg';
	}
}

function show_comment_author($author_name, $url)
{
	if(strlen($url) > 0) {
		return ' <a href="' . $url . '" target="_blank">' . htmlspec($author_name) . '</a>';
	} else {
		return htmlspec($author_name);
	}
}

$is_odd = TRUE;
foreach($comments as $cmt) {
?>
<div id="c<?php echo($cmt->id); ?>" class="comment <?php echo($is_odd ? 'odd' : 'even'); ?>">
	<div class="a"><img alt="" src="<?php echo(base_url() . 'img/avatars/' . get_avatar_name($cmt->by_blogger_id)); ?>" /></div>
	<div class="c">
		<div class="i">
			<?php echo(show_comment_author($cmt->author_name, $cmt->url) . ' @ ' . $cmt->post_time . $cmt->ip); ?>
		</div>
		<?php echo($cmt->content); ?>
	</div>
</div>
<?php
	$is_odd = !$is_odd;
}
?>
